package swa2012.telco.provider.broker;

import java.util.Collection;

import javax.jws.WebService;

import org.apache.cxf.feature.Features;

import swa2012.telco.broker.BrokerCallback;
import swa2012.telco.broker.beans.*;
import swa2012.telco.provider.ClientStorage;
import swa2012.telco.provider.MessageStorage;
import swa2012.telco.provider.TelcoProvider;

/**
 * @author kumar aberer
 * @date 10.06.2012
 */


@WebService(endpointInterface = "swa2012.telco.broker.BrokerCallback")
@Features(features = "org.apache.cxf.feature.LoggingFeature")
public class BrokerCallbackImpl implements BrokerCallback {
	
	private static BrokerCallbackImpl bc;
	private TelcoProvider provider;
	private static MessageStorage msgs;
	private static ClientStorage clients;
	
	private BrokerCallbackImpl(){
	}
	
	public static BrokerCallbackImpl getSingleInstance(){
		if (bc == null){
			bc = new BrokerCallbackImpl();
		}
		return bc;
			
	}
	
	public BrokerCallbackImpl(TelcoProvider provider, MessageStorage msgs, ClientStorage clients)
	  {
		System.out.println("neues object  konstruktor");
	     this.provider = provider;
	     this.clients = clients;
	     this.msgs = msgs;
	  }
	
	
	public TelcoProvider getProvider() {
		return provider;
	}

	public void setProvider(TelcoProvider provider) {
		this.provider = provider;
	}

	public MessageStorage getMsgs() {
		return msgs;
	}

	public void setMsgs(MessageStorage msgs) {
		this.msgs = msgs;
	}

	public ClientStorage getClients() {
		return clients;
	}

	public void setClients(ClientStorage clients) {
		this.clients = clients;
	}


	@Override
	public ReceiveMessageStatus receiveMessage(Message msg) {
		this.msgs.addMessage(msg);
		return ReceiveMessageStatus.RECEIVE_MESSAGE_OK;
	}

	@Override
	public Collection<Client> listClients() {
		System.out.println("broker callback: listclients");
		return clients.getClients();
	}

	@Override
	public boolean ping() {
		System.out.println("broker callback: ping");
		return true;
	}

}
